import { Button, message } from 'antd'
import {useEffect,useState} from 'react'
import caseApi from '../api/case.api'
import HTTP from '../services/api'
import SelfTable from '../tools/selfTable'
import{history} from 'umi'

const cloumns = [
  {
    dataIndex: 'apply',
    title: '绑定',
    width:'50'
  },
  {
    dataIndex: 'bigintr',
    title: '目前的情况',
    width:'50'
  },
  {
    dataIndex: 'blood_pressure',
    title: '血压',
    width:'50'
  },
  {
    dataIndex: 'breathing',
    title: '呼吸',
    width:'50'
  },
  {
    dataIndex: 'case_id',
    title: '',
    width:'50'
  },
  {
    dataIndex: 'case_out',
    title: '外出治疗的病例',
    width:'50'
  },
  {
    dataIndex: 'createdAt',
    title: '创建时间',
    width:'50'
  },
  {
    dataIndex: 'doctor_id',
    title: '看病医生id',
    width:'50'
  },
  {
    dataIndex: 'examination_result',
    title: '检查的结果  ',
    width:'50'
  },
  {
    dataIndex: 'nurse_id',
    title: '',
    width:'50'
  },
  {
    dataIndex: 'physical_evaluation',
    title: '体格评价  ',
    width:'50'
  },
  {
    dataIndex: 'prescription_id',
    title: '处方的编号',
    width:'50'
  },
  {
    dataIndex: 'pulse',
    title: '脉搏  ',
    width:'50'
  },
  {
    dataIndex: 'receipt',
    title: '回执  ',
    width:'50'
  },
  {
    dataIndex: 'student_id',
    title: '学生ID',
    width:'50'
  },
  {
    dataIndex: 'temperature',
    title: '体温  ',
    width:'50'
  },
  {
    dataIndex: 'updatedAt',
    title: '更新时间',
    width:'50'
  },
  {
    dataIndex: 'active',
    title: '操作',
    width:'50',
    render:(text,item)=><Button type="primary" shape="round" onClick={()=>{see(item.case_id)}}>查看具体的病例信息</Button>
  }

]
let scrollX = 0
cloumns.forEach(item=>{scrollX+=item.width})

const getCaseByLocalId = item =>{
    console.log(item)
    
    //todo
}

const see = (caseid) =>{
  console.log(caseid)
  history.push({pathname:'/prescription',query:{caseid:encodeURI(caseid)}})
}
function Case(){

    const [caseInfo,setCaseInfo] = useState([])
    const getCaseByWorkid = async()=>{
        let id = JSON.parse(localStorage.getItem('userinfo')).work_id
        console.log(id)
        let result = await HTTP({method:'get',id},caseApi.caseRestfu,{type:'work'})
        try{
            if(result.status){
                setCaseInfo(result.info.rows)
                message.success(result.msg)
            }else{
                message.error(result.msg)
            }
        }catch(error){
            message.error('服务器异常')

        }
    }

  

    useEffect(()=>{
        getCaseByWorkid()
    },[])

    return(
        <>
        <SelfTable isshowHeader columns={cloumns} dataSource={caseInfo} scroll={{x:scrollX}}  keyid='case_id' ></SelfTable>
        </>
    )
}


export default Case